
export function getRawOptions(showDays:number,xData:any[],tradeNumData:any[],tradeAmountData:any[]){
  const colors = ["#91CC75", "#EE6666"];
  return {
    title: { text: `近${showDays}天记账情况` },
    color: colors,
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "cross",
      },
    },
    grid: {
      right: "20%",
    },
    toolbox: {
      feature: {
        dataView: { show: true, readOnly: true },
        restore: { show: false },
        saveAsImage: { show: false },
      },
    },
    legend: {
      data: ["订单数", "交易额"],
    },
    xAxis: [
      {
        type: "category",
        axisTick: {
          alignWithLabel: true,
        },
        data: xData,
      },
    ],
    yAxis: [
      {
        type: "value",
        name: "订单数",
        position: "left",
        alignTicks: true,
        axisLine: {
          show: true,
          lineStyle: {
            color: colors[0],
          },
        },
        axisLabel: {
          formatter: "{value}",
        },
      },
      {
        type: "value",
        name: "交易额",
        position: "right",
        alignTicks: true,
        offset: 80,
        axisLine: {
          show: true,
          lineStyle: {
            color: colors[1],
          },
        },
        axisLabel: {
          formatter: "{value} ￥",
        },
      },
    ],
    series: [
      {
        name: "订单数",
        type: "line",
        yAxisIndex: 0,
        data: tradeNumData,
      },
      {
        name: "交易额",
        type: "bar",
        yAxisIndex: 1,
        data: tradeAmountData,
      },
    ],
  };

}

export function mockData(showDays:number) {
  const getLatestDays = (days = 20) => {
    let arr = [];
    const now = new Date();
    for (let i = 0; i < days; i++) {
      const d = new Date(now.getFullYear(), now.getMonth(), now.getDate() - i);
      // @ts-ignore
      arr.push(d.format("MM-dd"));
    }
    return arr.reverse();
  }
  let xData = getLatestDays(showDays) as [];
  let tradeNumData = [];
  let tradeAmountData = [];

  for (let i = 0; i < showDays; i++) {
    let num = Math.ceil(50 * Math.random());
    let amount = 0;
    for (let j = 0; j < num; j++) {
      if (Math.random() < 0.2) {
        amount += 45 + Math.round(5 * Math.random());
      } else {
        amount += 50;
      }
    }
    tradeNumData.push(num);
    tradeAmountData.push(amount);
  }
  return {
    xData:xData,
    tradeNumData:tradeNumData,
    tradeAmountData:tradeAmountData,
  }
}
